package com.jihui.jihuipicturebackend.utils;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;

import java.util.concurrent.TimeUnit;

public class CaffeineCacheUtil {
    // 构造本地缓存
    private static final Cache<String, String> LOCAL_CACHE =
            Caffeine.newBuilder().initialCapacity(1024)
                    .maximumSize(10000L)
                    // 缓存 5 分钟移除
                    .expireAfterWrite(5L, TimeUnit.MINUTES)
                    .build();
    // 查询缓存
    public static String getCaffeineCache(String key) {
        return LOCAL_CACHE.getIfPresent(key);
    }

    // 设置缓存
    public static void setCaffeineCache(String key, String value) {
        LOCAL_CACHE.put(key, value);
    }
}
